package com.shayu.aicodemother.service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.service.IService;
import com.shayu.aicodemother.model.dto.chathistory.ChatHistoryQueryRequest;
import com.shayu.aicodemother.model.entity.ChatHistory;
import com.shayu.aicodemother.model.entity.User;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;

import java.time.LocalDateTime;

/**
 * 对话历史 服务层。
 *
 * @author <a href="https://github.com/liyupi">程序员鲨鱼</a>
 */
public interface ChatHistoryService extends IService<ChatHistory> {


    /**
     * 将用户与ai的对话保存在数据库中
     * @param appId
     * @param message
     * @param messageType
     * @param userId
     * @return
     */
    boolean addChatMessage(Long appId, String message, String messageType, Long userId);

    /**
     * 删除应用，会话记忆同时删除
     * @param appId
     * @return
     */
    boolean deleteByAppId(Long appId);

    /**
     * 游标查询
     * @param appId
     * @param pageSize
     * @param lastCreateTime
     * @param loginUser
     * @return
     */
    Page<ChatHistory> listAppChatHistoryByPage(Long appId, int pageSize,
                                               LocalDateTime lastCreateTime,
                                               User loginUser);

    /**
     * 将历史对话添加到记忆中--内存
     * @param appid
     * @param chatMemory
     * @param maxCount
     * @return
     */
    int loadChatHistotyToMemory(Long appid, MessageWindowChatMemory chatMemory, int maxCount);

    /**
     * 获取查询包装类
     * @param chatHistoryQueryRequest
     * @return
     */
    QueryWrapper getQueryWrapper(ChatHistoryQueryRequest chatHistoryQueryRequest);
}
